from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime

class KnowledgeBaseBase(BaseModel):
    """知识库基础Schema"""
    name: str = Field(..., min_length=1, max_length=100)
    description: Optional[str] = None
    visibility: str = Field(default="private")  # private, shared, public
    
class KnowledgeBaseCreate(KnowledgeBaseBase):
    """创建知识库Schema"""
    pass

class KnowledgeBaseUpdate(BaseModel):
    """更新知识库Schema"""
    name: Optional[str] = Field(None, min_length=1, max_length=100)
    description: Optional[str] = None
    visibility: Optional[str] = None

class KnowledgeBaseResponse(KnowledgeBaseBase):
    """知识库响应Schema"""
    id: str
    owner_id: str
    owner_name: Optional[str]
    document_count: int = 0
    created_at: datetime
    updated_at: Optional[datetime]
    
    class Config:
        from_attributes = True

class KnowledgeBaseListResponse(BaseModel):
    """知识库列表响应Schema"""
    items: List[KnowledgeBaseResponse]
    total: int

